const EventEmitter = require("events");
EventEmitter.defaultMaxListeners = 10000
module.exports = class Events extends EventEmitter {
  constructor() {
    super();
    this._prop_event_single = new Map();
    this._single_bind_id_map = new Map();
  }
  emitPropChanged(propname, ...args) {
    const single = this._prop_event_single;
    if (single.get(propname)) {
      return;
    }
    single.set(propname, true);
    setImmediate(() => {
      single.set(propname, false);
      this.emit(propname + "Changed", this[propname], ...args);
      this.emit("*Changed", propname, this[propname], ...args);
    });
  }
  emitPropChangedSync(propname, ...args) {
    // const single = this._prop_event_single;
    // if (single.get(propname)) {
    //   return;
    // }
    // single.set(propname, true);
    this.emit(propname + "Changed", this[propname], ...args);
    this.emit("*Changed", propname, this[propname], ...args);
    // single.set(propname, false);
  }
  singleOn(eventname, handle, handle_id) {
    if (this._single_bind_id_map.get(handle_id)) {
      return;
    }
    this._single_bind_id_map.set(handle_id, true);
    super.on(eventname, handle);
  }
};
